package com.hsoft.zhxy.app.xtgl_02_01.service.impl;


import com.hsoft.zhxy.app.xtgl_02_01.mapper.JcggDmxXbMapper;
import com.hsoft.zhxy.app.common.model.entity.JcggDmxXb;
import com.hsoft.zhxy.app.xtgl_02_01.service.JcggDmxXbService;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.hsoft.zhxy.common.base.BaseService;
import com.hsoft.zhxy.common.result.ResultBody;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

 /**
 * All rights Reserved, Designed By 哈尔滨工业大学软件工程股份有限公司
 * 
 * @Title: 代码项校标 Service层接口实现类
 * @Package 
 * @Description: 
 * @author: system
 * @date: 2020-10-26
 */
@Log4j2
@Service
public class JcggDmxXbServiceImpl extends BaseService implements JcggDmxXbService {

    @Autowired
    private JcggDmxXbMapper jcggDmxXbMapper;


    /**
     * 查询单条数据
     * @param jcggDmxXb
     * @return
     */
    public JSONObject findOne(JcggDmxXb jcggDmxXb) {
        JcggDmxXb rs = jcggDmxXbMapper.selectOne(new QueryWrapper<JcggDmxXb>().setEntity(jcggDmxXb));
        return ResultBody.setData(rs);
    }


    /**
     * 查询列表数据
     * @param jcggDmxXb
     * @return
     */
    public JSONObject findList(JcggDmxXb jcggDmxXb) {
        List<JcggDmxXb> list = jcggDmxXbMapper.selectList(new QueryWrapper<JcggDmxXb>().setEntity(jcggDmxXb));
        return ResultBody.setData(list);
    }


    /**
     * 查询分页数据
     * @param jcggDmxXb
     * @param page
     * @param pageSize
     * @return
     */
    public JSONObject findListByPage(JcggDmxXb jcggDmxXb, long page, long pageSize) {

        Page<JcggDmxXb> pageObj = new Page<JcggDmxXb>(page, pageSize);
        IPage<JcggDmxXb> result = jcggDmxXbMapper.selectPage(pageObj, new QueryWrapper<JcggDmxXb>().setEntity(jcggDmxXb));

        return ResultBody.setData(result.getTotal(), result.getRecords());
    }


    /**
     * 新增
     * @param jcggDmxXb
     * @return
     */
    public JSONObject add(JcggDmxXb jcggDmxXb) {
        jcggDmxXb.setCjsj(LocalDateTime.now());
        jcggDmxXb.setCjr(getYhid());
        jcggDmxXb.setBgsj(LocalDateTime.now());
        jcggDmxXb.setBgr(getYhid());
        return ResultBody.setData(jcggDmxXbMapper.insert(jcggDmxXb));
    }


    /**
     * 修改
     * @param jcggDmxXb
     * @return
     */
    public JSONObject update(JcggDmxXb jcggDmxXb) {
        jcggDmxXb.setBgsj(LocalDateTime.now());
        jcggDmxXb.setBgr(getYhid());
        return ResultBody.setData(jcggDmxXbMapper.updateById(jcggDmxXb));
    }


    /**
     * 删除
     * @param jcggDmxXb
     * @return
     */
    public JSONObject delete(JcggDmxXb jcggDmxXb) {
        return ResultBody.setData(jcggDmxXbMapper.delete(new QueryWrapper<JcggDmxXb>().setEntity(jcggDmxXb)));
    }


}
